package com.pro.controller;

import com.pro.pojo.JsLoginRecord;
import com.pro.pojo.JsonData;
import com.pro.service.JsMenuLoginRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:JsMenuLoginRecordController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2022/3/18 下午 2:56
 * @Author: WYH
 */
@RestController
@RequestMapping("/LoRe")
public class JsMenuLoginRecordController {

    @Autowired
    private JsMenuLoginRecordService jsMenuLoginRecordService;

    /**
     * @Author WYH
     * @Description //TODO 查询后台人员登录日志
     * @Date 下午 3:00 2022/3/18
     * @Param account，trueName，limit，page
     * @return  JsonData
     **/
    @RequestMapping("/getAllJsLoginRecord")
    public JsonData getAllJsLoginRecord(String account, String trueName, Integer loginType,Integer limit, Integer page) {
        account = account != null && account != "" ? "%"+account+"%":"%%";
        trueName = trueName != null && trueName != "" ? "%"+trueName+"%":"%%";
        List<JsLoginRecord> allJsLoginRecord = jsMenuLoginRecordService.getAllJsLoginRecord(account, trueName, loginType,limit, page);
        Integer integer = jsMenuLoginRecordService.countLoginRecord(account, trueName, loginType);
        return allJsLoginRecord != null ? JsonData.buildSuccess(allJsLoginRecord,integer) : JsonData.buildError("数据格式异常") ;
    }

    /**
     * @Author WYH
     * @Description //TODO 查询前台人员登录日志
     * @Date 下午 3:00 2022/3/18
     * @Param account，trueName，limit，page
     * @return  JsonData
     **/
    @RequestMapping("/getAllJsLoginRecordbefore")
    public JsonData getAllJsLoginRecordbefore(String account, String nickname, Integer loginType,Integer limit, Integer page) {
        account = account != null && account != "" ? "%"+account+"%":"%%";
        nickname = nickname != null && nickname != "" ? "%"+nickname+"%":"%%";
        List<JsLoginRecord> allJsLoginRecord = jsMenuLoginRecordService.getAllJsLoginRecordbefore(account, nickname, loginType,limit, page);
        Integer integer = jsMenuLoginRecordService.countLoginRecordbefore(account, nickname, loginType);
        return allJsLoginRecord != null ? JsonData.buildSuccess(allJsLoginRecord,integer) : JsonData.buildError("数据格式异常") ;
    }

    /**
     * @Author WYH
     * @Description //TODO 删除登录日志
     * @Date 下午 4:25 2022/3/18
     * @Param id
     * @return JsonData
     **/
    @RequestMapping("/delLooginUser")
    public JsonData delLooginUser(Integer id){
        Boolean aBoolean = jsMenuLoginRecordService.delLooginUser(id);
        return aBoolean ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("数据格式异常");
    }
}
